import { ref, onMounted } from "vue";
import { getDataBySQLDesc, type SQLParams } from "@/api/common";

export function useCommonDictionary(dictSQLData: any) {
  const dicData = ref<any[]>([]);
  const loading = ref(false);
  const error = ref<Error | null>(null);

  const fetchDictionary = async (params?: any) => {
    loading.value = true;
    error.value = null;
    try {
      // 根据实际情况替换接口地址
      const response = await getDataBySQLDesc(params || dictSQLData);
      // 处理字典的结构
      dicData.value = response.data;
    } catch (err) {
      error.value = err as Error;
    } finally {
      loading.value = false;
    }
  };

  onMounted(() => {
    fetchDictionary();
  });

  return { dicData, loading, error, fetchDictionary };
}
